package com.lyEducation.controllers.dto.system;

import com.lyEducation.util.StringUtils;
import com.lyEducation.util.controllerUtil.JsonResult;
import lombok.Getter;

import java.util.List;
import java.util.TreeSet;

@Getter
public class InsertUpdSysMenuDto extends AbstractSysMenuDto {
    private List<String> roleIdList;

    public InsertUpdSysMenuDto() {
        super();
    }

    private InsertUpdSysMenuDto(
            String id,
            String parentId,
            TreeSet<SysMenuDto> childMenus,
            List<String> roleIdList,
            String name,
            int status,
            String url,
            int level,
            int sort) {
        this.setId(id);
        this.setParentId(parentId);
        //        this.setChildMenus(childMenus);
        this.roleIdList = roleIdList;
        this.setName(name);
        this.setStatus(status);
        this.setUrl(url);
        this.setLevel(level);
        this.setSort(sort);
    }

    private boolean isNeedChildMenuRole;

    public void setIsNeedChildMenuRole(boolean isNeedChildMenuRole) {
        this.isNeedChildMenuRole = isNeedChildMenuRole;
    }

    public JsonResult checkUrl() {
        int length = 500;
        if (StringUtils.isBlank(this.getUrl())) {
            return JsonResult.putFail("菜单url不能为空");
        }
        if (this.getUrl().length() > length) {
            return JsonResult.putFail("菜单url长度超过限制,长度不能超过" + length + "个字符");
        }
        return null;
    }
}
